<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            document.getElementById('btn').addEventListener('click', function () {
                console.log('button clicked');
            });
            console.log('DOMContentLoaded');
        });
    </script>
</head>

<body>
    <button id="btn"> Click Me!</button>
    <script>
        function handleReady() {
            console.log('DOMContentLoaded');
        }

        if (document.readyState === 'loading') {
            console.log('loading');
            document.addEventListener('DOMContentLoaded', handleReady);
        } else {
            console.log('DOMContentLoaded');
            handleReady();
        }

    </script>
</body>

</html>